package org.jeecg;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import org.jeecg.common.util.PasswordUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.tools.MyTestUtil;
import org.jeecg.tools.RowMappers;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import com.voucher.manage.daoSQL.InsertSQL;


public class shiropass {

	public static void main(String[] args) {
		
		String username="admin08";
		String password="123";
		
		String salt = oConvertUtils.randomGen(8);
		String passwordEncode = PasswordUtil.encrypt(username, password, salt);
		
		System.out.println("passwordEncode=     "+passwordEncode);
		System.out.println("salt=     "+salt);
		
		DriverManagerDataSource dataSource = new DriverManagerDataSource();
		dataSource.setDriverClassName("org.springframework.jdbc.core.JdbcTemplate");
		dataSource.setUrl("jdbc:mysql://223.86.150.188:3306/jeecg?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true");
		dataSource.setUsername("xlroot");
		dataSource.setPassword("fhc123456");
		
		JdbcTemplate getJdbcTemplate= new JdbcTemplate();
		
		getJdbcTemplate.setDataSource(dataSource);
		
		String sql="select * from sys_permission where create_time >'2020-04-03 18:48:00'";
				
		List list=new ArrayList<>();
		try{
			list=getJdbcTemplate.query(sql,new RowMappers(Sys_permission.class));
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		Iterator iterator=list.iterator();
		
		Random r = new Random();
		StringBuilder rs = new StringBuilder();
		for (int i = 0; i < 19; i++) {
			rs.append(r.nextInt(10));
		 }
		
		String parentId=rs.toString();
		
		while (iterator.hasNext()) {
			
			Sys_permission sys_permission=(Sys_permission) iterator.next();
			
			sys_permission.setCreate_by("jeecg");
			
			sys_permission.setParent_id(parentId);
			
			Random r2 = new Random();
			StringBuilder rs2 = new StringBuilder();
			for (int i = 0; i < 19; i++) {
				rs2.append(r2.nextInt(10));
			 }
			
			String id=rs2.toString();
			
			if(sys_permission.getMenu_type()==0){
				sys_permission.setId(parentId);
			}else{
				sys_permission.setId(id);
			}
			Map map=new HashMap<>();
			
			try {
				map=InsertSQL.get(sys_permission);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			sql=(String) map.get("sql");
			List params=(List) map.get("pamars");

			int i=getJdbcTemplate.update(sql,params.toArray());
		}
		
	}

	
}
